'''
封装页面对象共性的操作
'''
import logging
import time

import yaml
from selenium import webdriver


class BasePage:
    _base_url = None
    def __init__(self, base_driver=None):
        if base_driver:
            self.driver = base_driver
        else:
            self.driver = webdriver.Chrome()
            # Unable no element
            self.driver.implicitly_wait(3)
            if self._base_url is not None:
                self.driver.get(self._base_url)
                cookie = yaml.safe_load(open("../data/cookie.yaml"))
                # 3. 植入cookie
                for c in cookie:
                    self.driver.add_cookie(c)
                time.sleep(3)
                # 4.再次访问企业微信页面，发现无需扫码自动登录，而且可以多次使用
                self.driver.get(self._base_url)

    def find(self, by, locaotr=None):
        # 解包操作
        if locaotr == None:
            # 这个地方判断第二个参数是否为空，如果为空则进行解包操作
            res = self.driver.find_element(*by)

        else:
            res = self.driver.find_element(by, locaotr)


        print(f"找到元素{res}")
        return res
